<?php
// application/controllers/TblproduitController.php

class TblproduitController extends Zend_Controller_Action
{
    public function indexAction()
    {
        $tblproduit = new Application_Model_TblproduitMapper();
        $this->view->entries = $tblproduit->fetchAll();
    }
    
    
    public function deleteAction() {
        $this->view->delete_id = $this->getRequest()->getParam('delete_id');
        $mapper = new Application_Model_TblproduitMapper();
        $mapper->deleteById($this->view->delete_id);

        return $this->_helper->redirector('index');
    }

    public function signAction()
    {
        $request = $this->getRequest();
        $form    = new Application_Form_Tblproduit();

        if ($this->getRequest()->isPost()) {
            if ($form->isValid($request->getPost())) {
                $allValue = new Application_Model_Tblproduit($form->getValues());
                $mapper  = new Application_Model_TblproduitMapper();
                $mapper->save($allValue);
                   return $this->_helper->redirector('index');
            }
        }

        $this->view->form = $form;
    }
    public function editAction() {
        $form = new Application_Form_Tblproduit ( );
        $form->setIdTblproduit($this->getRequest()->getParam('id'));
        $form->init();
        $this->view->formUserEdit = $form;

        if ($this->_request->isPost()) {
            $formData = $this->_request->getPost();
            if ($form->isValid($formData)) {
                $company = new Application_Model_DbTable_Tblproduit ( );
                unset($formData ['submit']);
                $where = $company->getAdapter()->quoteInto('id = ?', $this->getRequest()->getParam('id'));               
                $result = $company->update($formData, $where);

                if ($result) {
                    $this->_helper->redirector('index', 'Tblproduit', '', array('' => ''));
                } else {
                    $this->_helper->redirector('index', 'Tblproduit', '', array('' => ''));
                }
            }
        }
    }
}
